package gui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;

/**
 * @file PartPurchases.java
 * @version 0.1
 * @author James Dibble 10009689
 */
@Entity
@Table(name = "part_purchases", catalog = "dms", schema = "")
@NamedQueries({
    @NamedQuery(name = "PartPurchases.findAll", query = "SELECT p FROM PartPurchases p"),
    @NamedQuery(name = "PartPurchases.findById", query = "SELECT p FROM PartPurchases p WHERE p.id = :id"),
    @NamedQuery(name = "PartPurchases.findByPurchasePrice", query = "SELECT p FROM PartPurchases p WHERE p.purchasePrice = :purchasePrice"),
    @NamedQuery(name = "PartPurchases.findByPurchaseDate", query = "SELECT p FROM PartPurchases p WHERE p.purchaseDate = :purchaseDate"),
    @NamedQuery(name = "PartPurchases.findByPart", query = "SELECT p FROM PartPurchases p WHERE p.part = :part"),
    @NamedQuery(name = "PartPurchases.findByQtyPurchased", query = "SELECT p FROM PartPurchases p WHERE p.qtyPurchased = :qtyPurchased"),
    @NamedQuery(name = "PartPurchases.findByBatch", query = "SELECT p FROM PartPurchases p WHERE p.batch = :batch")})
public class PartPurchases implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "purchase_price")
    private long purchasePrice;
    @Basic(optional = false)
    @Column(name = "purchase_date")
    @Temporal(TemporalType.DATE)
    private Date purchaseDate;
    @Basic(optional = false)
    @Column(name = "part")
    private int part;
    @Basic(optional = false)
    @Column(name = "qty_purchased")
    private int qtyPurchased;
    @Basic(optional = false)
    @Column(name = "batch")
    private String batch;
    // <editor-fold defaultstate="collapsed" desc="Attributes">
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public PartPurchases() {
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Methods">
    // </editor-fold>

    public PartPurchases(Integer id) {
        this.id = id;
    }

    public PartPurchases(Integer id, long purchasePrice, Date purchaseDate, int part, int qtyPurchased, String batch) {
        this.id = id;
        this.purchasePrice = purchasePrice;
        this.purchaseDate = purchaseDate;
        this.part = part;
        this.qtyPurchased = qtyPurchased;
        this.batch = batch;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public long getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(long purchasePrice) {
        long oldPurchasePrice = this.purchasePrice;
        this.purchasePrice = purchasePrice;
        changeSupport.firePropertyChange("purchasePrice", oldPurchasePrice, purchasePrice);
    }

    public Date getPurchaseDate() {
        return purchaseDate;
    }

    public void setPurchaseDate(Date purchaseDate) {
        Date oldPurchaseDate = this.purchaseDate;
        this.purchaseDate = purchaseDate;
        changeSupport.firePropertyChange("purchaseDate", oldPurchaseDate, purchaseDate);
    }

    public int getPart() {
        return part;
    }

    public void setPart(int part) {
        int oldPart = this.part;
        this.part = part;
        changeSupport.firePropertyChange("part", oldPart, part);
    }

    public int getQtyPurchased() {
        return qtyPurchased;
    }

    public void setQtyPurchased(int qtyPurchased) {
        int oldQtyPurchased = this.qtyPurchased;
        this.qtyPurchased = qtyPurchased;
        changeSupport.firePropertyChange("qtyPurchased", oldQtyPurchased, qtyPurchased);
    }

    public String getBatch() {
        return batch;
    }

    public void setBatch(String batch) {
        String oldBatch = this.batch;
        this.batch = batch;
        changeSupport.firePropertyChange("batch", oldBatch, batch);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PartPurchases)) {
            return false;
        }
        PartPurchases other = (PartPurchases) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "gui.PartPurchases[ id=" + id + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
